# 指定cmake版本
cmake_minimum_required(VERSION 3.15.0)

# 工程名称
project(mvAcquisitionServer)

# cmake的C++设置 已在toolchain_options.cmake设置了
#set(CMAKE_CXX_STANDARD 14)

# 添加预定义宏 
MESSAGE(INFO "--------------------------------")
# 是否打印输出
option(ENABLE_TRACE_PRINTF "option for trace" ON)
if (ENABLE_TRACE_PRINTF) 
	add_definitions(-DENABLE_TRACE_PRINTF)
endif(ENABLE_TRACE_PRINTF)
# 是否打印日志
option(ENABLE_LOG_PRINTF "option for log" ON)
if (ENABLE_LOG_PRINTF) 
	add_definitions(-DENABLE_LOG_PRINTF)
endif(ENABLE_LOG_PRINTF)

MESSAGE(STATUS "CMAKE_CURRENT_SOURCE_DIR : ${CMAKE_CURRENT_SOURCE_DIR}")
MESSAGE(STATUS "option for log : ${ENABLE_LOG_PRINTF}")
# 字符集使用unicode
#add_definitions(-DUNICODE -D_UNICODE)

# 移除警告信息
add_definitions(-w -g -Wall -O2 -rdynamic)
# 启用pkg_check_modules加载依赖库
#include(FindPkgConfig)
#pkg_check_modules (GLIB REQUIRED IMPORTED_TARGET glib-2.0)
#pkg_check_modules (DBUS REQUIRED IMPORTED_TARGET dbus-1)
#pkg_check_modules (SQLITE3 REQUIRED IMPORTED_TARGET sqlite3)
# 遍历头文件
file(GLOB_RECURSE headerFiles "${PROJECT_SOURCE_DIR}/*.hpp" "${PROJECT_SOURCE_DIR}/*.h")
# 遍历源文件
file(GLOB_RECURSE srcFiles "${PROJECT_SOURCE_DIR}/*.cpp" "${PROJECT_SOURCE_DIR}/*.c")

# 输出遍历文件信息
MESSAGE(STATUS "Build headerFiles: ${headerFiles}")
MESSAGE(STATUS "Build srcFiles: ${srcFiles}")

# 添加编译文件
add_executable(${PROJECT_NAME}
	${headerFiles}
	${srcFiles}
	)

#IF(DEFINED TPROJECT_VERSION)
#	MESSAGE(STATUS " TPROJECT_VERSION: ${TPROJECT_VERSION}")
#	SET_TARGET_PROPERTIES (${PROJECT_NAME} PROPERTIES VERSION ${TPROJECT_VERSION} SOVERSION 1 )
#ENDIF()

# 链接库文件
target_link_libraries(${PROJECT_NAME}
PUBLIC 
	#PkgConfig::GLIB
	#PkgConfig::DBUS  
	#PkgConfig::SQLITE3
	${JSONCPP_LIBS}
	#serialLib_static
	#${OPENSSL_LIBS}
	#mvTsl_static
	uuid
	ZLToolKit_static
	dl
	rt 
	pthread
	${PROJECT_ROOT}/src/mv_acquisition_server/common/push/lib/libMVPushCUDP.so
	${PROJECT_ROOT}/src/mv_acquisition_server/common/sharememory/lib/libShmIPCPubApi.so
	${PROJECT_ROOT}/src/mv_acquisition_server/common/sharememory/lib/libShmIPCSubApi.so
	${PROJECT_ROOT}/src/mv_acquisition_server/common/heartbeat/lib/libmv_heartbeat.so
	)

# 加载依赖库
target_link_directories(${PROJECT_NAME}
PUBLIC 
	#${JSONCPP_LIBRARY_DIR}
	#${CURL_LIBRARY_DIR}
	#${OPENSSL_LIBRARY_DIR}
	#${PROJECT_ROOT}/src/ftmqtt_core
	#${PAHO_MQTTC_LIBRARY_DIR}
)	
# 加载源文件
# 加载库依赖头
target_include_directories(${PROJECT_NAME}
PUBLIC 
	${PROJECT_SOURCE_DIR}
	${PROJECT_ROOT}/3rdparty/ToolKit/src/ZLToolKit
	${JSONCPP_INCLUDE_DIR}
	${PROJECT_ROOT}/src/mv_acquisition_server/common/push/include
	#${PROJECT_ROOT}/src/lib_serial
	#${OPENSSL_INCLUDE_DIR}
	#${PROJECT_ROOT}/src/mv_tsl
	#${PAHO_MQTTC_INCLUDE_DIR}
	)
# 安装头文件
INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
    DESTINATION ${CMAKE_INSTALL_PREFIX}/include
    FILES_MATCHING
    PATTERN "*.h"
    PATTERN "*.hpp" 
	PATTERN "CMakeLists.txt" EXCLUDE
    )
# 安装文件
INSTALL(TARGETS ${PROJECT_NAME}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
    RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX})
# 安装配置文件
#install(FILES ${PROJECT_ROOT}/conf/dbus/upserver.conf
#	#DESTINATION /usr/share/dbus-1/system.d
#	DESTINATION ${CMAKE_INSTALL_PREFIX})



